package com.example.mapper;

import com.example.pojo.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {
    //查询所有题目
    @Select("SELECT id, content, correct_answer_index, options FROM questions")
    List<Question> getAllQuestions();

    //根据id查询题目
    @Select("SELECT id, content, options, correct_answer_index FROM questions WHERE id = #{id}")
    Question getQuestionById(Integer id);

    //插入题目
    @Insert("INSERT INTO questions (content, options, correct_answer_index)" +
            "VALUES (#{content}, #{optionsAsJson}, #{correctAnswerIndex})")
    void insertQuestion(Question question);

    //检查用户答案
    @Select("SELECT correct_answer_index FROM questions WHERE id = #{id}")
    Integer getCorrectAnswerIndex(Integer id);
}
